import InitData from './initData'
import InitFunc from './initFunc'
import StarView from '../coms/star/index.vue'

export default () => ({
    name: 'calendar',
    /*
        // 满
          [
            '2019/4/20',
            '2019/4/14',
            ]
        fullDate: [],
        // 已选
            [
            '2019/4/12',
            ]
        selecteds: [],
        price: 450,
    */
    props: ['nowD', 'cb', 'open', 'close', 'fullDate', 'selecteds', 'price'],
    data: InitData,
    components: {
        StarView,
    },
    watch: {
        nowD(val){
            this.nowD = val
        },
        fullDate(v){
            console.log('fullDate val')
            console.log(v)
            this.fullDate = v
        },
        selecteds(v){this.selecteds = v},
        price(v){this.price = v},
        open(val){
            this.clear()
            this.open = val
            this.init()
        }
    },
    created() {
        this.init()
    },
    mounted() {
        
    },
    beforeDestroy() {
    },
    methods: {
        //初始化
        init: InitFunc,
        siteTouch(e){
            let target = e.target
            // console.log(target) 
            let selectInfoStr = target.getAttribute('data-clickTg')
            if(!selectInfoStr){
                return
            }
            let selectInfo = JSON.parse(selectInfoStr)
            let timev = selectInfo.timev
            let timeVal = timev.replace(/\//g, '-')
            if(!timev){
                return
            }
            // 之前的时间
            if(+new Date(timev) < +new Date(this.nowTimeStr)){
                return
            }
            // 超过15天
            if(+new Date(timev) > +new Date(this.nowTimeStr) + (1000 * 60 * 60 * 24 * 14)){
                return
            }
            // 已满
            if(this.fullDate.includes(timev)){
                return
            }
            let data = new Date(timev)
            console.log(timev)
            console.log(data)
            if(this.selecteds.includes(timev)){
                this.selecteds = this.selecteds.filter(e => e !== timev)
            }else{
                if(this.selecteds.length >= 8){
                    this.$toast('最多预约8天哦')
                }else{
                    this.selecteds.push(timev)
                }
            }
        },
        isTimeCenter(a, b, v){
            return a && b && new Date(v) > new Date(a) && new Date(v) < new Date(b)
        },
        clearOp(){
            if(!this.startTime || !this.endTime){
                return
            }
            this.clear()
        },
        clear(){
            this.startTime = ''
            this.startTime2 = ''
            this.endTime = ''
            this.endTime2 = ''
        },
        success(){
            this.cb && this.cb(this.selecteds)
        },
        delectSelected(item){
            console.log(item)
            this.selecteds = this.selecteds.filter(e => e !== item)
        },
        selectRange(index){
            // 所有
            let list = this.list[0].m
            // 今天
            let date = this.nowTimeStr
            // 满的
            let fullDate = this.fullDate
            let selecteds
            let isStart = false
            let count = 0
            selecteds = list.map(e => e.timev)
                .filter((e) => {
                    if(e === date){
                        isStart = true
                    }
                    if(isStart){
                        if(fullDate.includes(e)){
                            return false
                        }
                        count += 1
                        if(count <= index){
                            return true
                        }                
                    }
                    return false
                })
            this.selecteds = selecteds
        },
        _close(){
            this.close()
        },
        tip(){
            TESTVUE.$dialog.alert({
                title: '说明',
                messageAlign: 'left',
                message: `1、请您先行点选您所要作图的张数，按照您所选张数、和表现师的空闲时间，会顺序默认选中相应的天数，若您有其他时间安排上的想法，也可手动点选修改作图的日期（系统默认一张图会占用一天的时间，若一天可以完成两张图可提前结束作图时间）\n2、若您的时间安排与表现师空闲时间不符，例如第二天需要见客户，当天需要完成两张图，建议您可再下单另一位表现师，二人同时上门为您服务！价钱合理，方便快捷；\n3、360全景效果图的收费价格为表现师时价的1.5倍；`
            })
        }
    }
})